The following example illustrates how to use a movie data export component to export audio data to an AIFF file.
The first step in using a movie data export component to create an AIFF file is instantiating an AIFF data export component. An example of this is shown in Listing 3 .
Listing 3 Instantiating a data export component
ComponentDescription cd;
MovieExportComponent ci;
cd.componentType = MovieExportType;
cd.componentSubType = 'AIFF';
cd.componentManufacturer = SoundMediaType;
cd.componentFlags = canMovieExportFromProcedures;
cd.componentFlagsMask = canMovieExportFromProcedures;
ci = OpenComponent(FindNextComponent(nil, &cd));
Note that the componentManufacturer field holds the SoundMediaType if the movie contains sampled sound or `musi' if it contains MIDI music. If you pass a zero in this field, QuickTime will use the first exporter that can create the desired type of output. This will not always produce the desired result, as a component that creates AIFF output from MIDI requires different input that a component that creates AIFF output from sampled sound.
Note that Listing 3 uses the canMovieExportFromProcedures flag to limit the search to exporters that support the MovieExportFromProceduresToDataRef component call This is important since not all exporters implement this routine.
Once an AIFF movie data export component has been instantiated, it must be configured to open a single output audio stream. Listing 4 is an example of creating an output audio stream by calling MovieExportAddDataSource. In this example, MovieExportAddDataSource also provides the callback functions for supplying media data.
Listing 4 Configuring the audio export component
#define kMySampleRate 22050
#define kSoundBufferSize 1024
typedef struct
{
Ptr soundData;
SoundDescriptionHandle soundDescription;
long trackID;
}
MyReferenceRecord;
MyReferenceRecord myRef;
SoundDescriptionPtr sdp;
myRef.soundData = NewPtr(kSoundBufferSize);
myRef.soundDescription = NewHandleClear(sizeof(SoundDescription));
sdp = *myRef.soundDescription;
sdp->descSize = sizeof(SoundDescription);
sdp->dataFormat = k8BitOffsetBinaryFormat;
sdp->numChannels = 1;
sdp->sampleSize = 8;
sdp->sampleRate = kMySampleRate << 16;
MovieExportAddDataSource(ci, SoundMediaType, kMySampleRate,
&myRef.trackID, getSoundTrackPropertyProc,
getSoundTrackDataProc, &myRef);
On Macintosh PowerPC computers, the getSoundTrackPropertyProc and getSoundTrackDataProc routines should be universal procedure pointers (UPPs).
The export operation takes place when all of the required output tracks have been created.
Listing 5 Exporting audio data
StandardFileReply reply;
Handle dataRef;
// get output file from user
QTNewAlias(&reply.sfFile, (AliasHandle *)&dataRef, true);
// make up a data reference
MovieExportFromProceduresToDataRef(ci, dataRef, rAliasType);
MovieExportFromProceduresToDataRef calls the two functions specified in MovieExportAddDataSource to obtain data to generate the output file. The first function returns information about the output track's properties, including the sample rate and supported media. If no value is returned for a particular property, the exporter specifies a default value based on the source data format. In the example in Listing 6 , the output sample rate is set at 32000 Hz, with all other properties left unspecified.
Listing 6 Obtaining output track information
pascal OSErr getSoundTrackDataProc(void *refcon, long trackID,
OSType propertyType, void *propertyValue)
{
OSErr err = noErr;
switch (propertyType)
{
case scSoundSampleRateType:
*(Fixed *)propertyValue = 32000L << 16;
break;
default:
err = paramErr;
break;
}
return err;
}
The second function provides data to be exported. Listing 7 shows a block of sound data (silence) returned for each export request. The export operation ends when this function returns eofErr .
Listing 7 Providing output track information to the export component
pascal OSErr getSoundTrack(void *refCon,
MovieExportGetDataParams *params)
{
MyReferenceRecord *myRef = (MyReferenceRecord *)refCon;
if (params->requestedTime > kMySampleRate * 10)
return eofErr; // end of data after 10 seconds
params->dataPtr = myRef->soundData;
params->dataSize = kSoundBufferSize;
params->actualTime = params->requestedTime;
params->sampleCount = kSoundBufferSize;
params->durationPerSample = 1;
params->descType = SoundMediaType;
params->descSeed = 1;
params->desc = (SampleDescriptionHandle)myRef->soundDescription;
return noErr;
}
| Previous | Chapter Contents | Chapter Top | Next |